package com.sdp.flow.listener;

import org.flowable.engine.RuntimeService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.stereotype.Component;

import com.sdp.core.bizc.utils.ApplicationContextUtils;
import com.sdp.flow.utils.FlowConstants;

/*
 * 在这里springboot的注入没有作用
 */
@Component
public class TaskTestListener implements ExecutionListener {
	
	private static final long serialVersionUID = 3886640480557350064L;

	@Override
	public void notify(DelegateExecution execution) {
		// TODO Auto-generated method stub
		RuntimeService runtimeService = ApplicationContextUtils.getBean(RuntimeService.class);
		ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(execution.getProcessInstanceId())
			.singleResult();
		execution.setVariable(FlowConstants.FLOW_ASSIGN_PERSON_KEY, processInstance.getStartUserId());
	}

}
